VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsParticleHandler"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'====================================================================================
'clsParticleHandler - Manages the little floaty hearts and symbols in the game
'====================================================================================
Option Explicit

Public OffsetX As Long      'A horizontal offset to allow for scrolling screens
Public OffsetY As Long      'A vertical offset to allow for scrolling screens

Private Items As New Collection         'All particles on screen
Private ParticleGfx(10) As New ImageDC  'The Particle sprite images
Public Enum PM_PARTICLETYPE
    PT_200POINTS = 1        'The "+200" after eating 1 ghost
    PT_400POINTS = 2        'The "+400" after eating 2 ghosts in a row
    PT_800POINTS = 3        'The "+800" after eating 3 ghosts in a row
    PT_1600POINTS = 4       'The "+1600" after eating 4 ghosts in a row
    PT_HEART = 5            'The little hearts that trail behind the ghosts
    PT_DEATH = 6            'The skull and crossbones
    PT_1UP = 7              'The "+1up" after getting 10'000 points
    PT_COOKIE1 = 8          'One type of cookie
    PT_COOKIE2 = 9          'Another type of cookie
    PT_X2 = 10              '2x multiplier
End Enum

'====================================================================================
'CLASS Initialize
'====================================================================================
Private Sub Class_Initialize()
    'Load the particles
    ParticleGfx(PT_HEART).CreateFromPicture LoadPicture(AppPath & "\gfx\Particles\SmallHeart.bmp"), vbMagenta
    ParticleGfx(PT_200POINTS).CreateFromPicture LoadPicture(AppPath & "\gfx\Particles\+200.bmp"), vbMagenta
    ParticleGfx(PT_400POINTS).CreateFromPicture LoadPicture(AppPath & "\gfx\Particles\+400.bmp"), vbMagenta
    ParticleGfx(PT_800POINTS).CreateFromPicture LoadPicture(AppPath & "\gfx\Particles\+800.bmp"), vbMagenta
    ParticleGfx(PT_1600POINTS).CreateFromPicture LoadPicture(AppPath & "\gfx\Particles\+1600.bmp"), vbMagenta
    ParticleGfx(PT_DEATH).CreateFromPicture LoadPicture(AppPath & "\gfx\Particles\Death.bmp"), vbMagenta
    ParticleGfx(PT_1UP).CreateFromPicture LoadPicture(AppPath & "\gfx\Particles\+1up.bmp"), vbMagenta
    ParticleGfx(PT_COOKIE1).CreateFromPicture LoadPicture(AppPath & "\gfx\Particles\Cookie1.bmp"), vbMagenta
    ParticleGfx(PT_COOKIE2).CreateFromPicture LoadPicture(AppPath & "\gfx\Particles\Cookie2.bmp"), vbMagenta
    ParticleGfx(PT_X2).CreateFromPicture LoadPicture(AppPath & "\gfx\Particles\x2.bmp"), vbMagenta
End Sub

'====================================================================================
'Create: Add a sprite particle onto the level
'====================================================================================
Public Sub Create(ByVal ParticleType As PM_PARTICLETYPE, ByVal X As Long, ByVal Y As Long, ByVal LifeSpan As Long)
    '"Particles" are small sprites that float on the level. For example when you
    'Eat ghosts the points added appears and floats off.
    
    'Create a blank particle and assign the properties to it
    Dim NewParticle As New clsParticle
    NewParticle.AssignProperties ParticleType, X, Y, LifeSpan
    
    'Add the particle to our collection of all particles
    Items.Add NewParticle, NewParticle.ID
    
    'Clear the temporary particle
    Set NewParticle = Nothing
End Sub

'====================================================================================
'ClearAll: Remove all particles
'====================================================================================
Public Sub ClearAll()
    'Delete any existing particles on the level
    Dim PParticle As clsParticle
    For Each PParticle In Items
        Items.Remove PParticle.ID
    Next
End Sub

'====================================================================================
'Animate: Animate the particles
'====================================================================================
Public Sub Animate()
    'Animate the particles
    Dim PParticle As clsParticle
    For Each PParticle In Items
        'Move the particle in it's wavey pattern
        PParticle.Move
        'Reduce the life of the particle and remove if at end of lifespan
        PParticle.Life = PParticle.Life - 1
        If PParticle.Life = 0 Then Items.Remove PParticle.ID
    Next
End Sub

'====================================================================================
'Render: Draw all the particles onto a surface
'====================================================================================
Public Sub Render(ByVal hDC As Long)
    Dim PParticle As clsParticle
    For Each PParticle In Items
        'Draw the image
        ParticleGfx(PParticle.ParticleType).Draw hDC, (PParticle.X - OffsetX), (PParticle.Y - OffsetY)
        'If 2x Multiplier is applied, draw "x2" particle next to score particles
        If Project.GameMode = GM_Play Then
            If Level.PickupType = PT_GOOD_MULTIPLIER And PParticle.ParticleType <= 4 Then
                ParticleGfx(PT_X2).Draw hDC, (PParticle.X - OffsetX) + ParticleGfx(PParticle.ParticleType).Width, (PParticle.Y - OffsetY) + 4
            End If
        End If
    Next
End Sub

'====================================================================================
'CLASS Terminate: When the class is unloaded, free up used memory
'====================================================================================
Private Sub Class_Terminate()
    Erase ParticleGfx
    Set Items = Nothing
End Sub

'=== END ============================================================================
'This work is licenced under the Creative Commons Attribution 2.5 License
